//
//  XYPresentationController.swift
//  SinaWeibo
//
//  Created by 韩啸宇 on 15/12/25.
//  Copyright © 2015年 backy. All rights reserved.
//

import UIKit

class XYPresentationController: UIPresentationController {

    /// 弹出菜单尺寸
    var presentSize = CGSizeZero
    
    /// 布局弹出控制器的视图
    override func containerViewWillLayoutSubviews() {
        presentedView()?.frame.size.width = presentSize.width
        presentedView()?.frame.size.height = presentSize.height
        presentedView()?.center.x = (containerView?.frame.size.width)! / 2
        presentedView()?.frame.origin.y = 64
        
        containerView?.insertSubview(dismissButton, atIndex: 0)
    }

    // MARK: - 懒加载
    lazy var dismissButton: UIButton = {
        let button = UIButton()
        button.frame = UIScreen.mainScreen().bounds
        button.backgroundColor = UIColor(white: 0.5, alpha: 0.5)
        button.addTarget(self, action: Selector("dismissBtnClick"), forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
    // MARK: - 事件监听
    @objc private func dismissBtnClick() {
        presentingViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}
